home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / The GIMP 2.2.8 / gimp-2.2.8-i586-setup.exe / {app} / share / gimp / 2.0 / scripts / selection-round.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2005-06-30  |  5.7 KB  |  175 lines

  1. ;; selection-rounded-rectangle.scm -*-scheme-*- 
  2.  
  3. ;; The GIMP -- an image manipulation program
  4. ;; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  5. ;; 
  6. ;; This program is free software; you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation; either version 2 of the License, or
  9. ;; (at your option) any later version.  
  10. ;; 
  11. ;; This program is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. ;; GNU General Public License for more details.
  15. ;; 
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with this program; if not, write to the Free Software
  18. ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20. ;; CHANGE-LOG:
  21. ;; 1.00 - initial release
  22. ;; 1.01 - some code cleanup, no real changes
  23. ;; 1.02 - made script undoable
  24.  
  25. ;; 2.00 - ALAN's Branch.  changed name, menu, location, and description
  26. ;; 2.01 - fixed to work if there was no current selection. 
  27. ;; 2.02 - changed scale to percentages, usability tweaking.  
  28. ;; 2.10 - added concave round edges, updated description.  
  29. ;; 2.11 - tweeked description, changed comments, relinquished any rights.  
  30.  
  31. ;; Copyright (C) 1997, 1998, Sven Neumann
  32. ;; Copyright (C) 2004, Alan Horkan.  
  33. ;; Alan Horkan relinquishes all rights to his changes, 
  34. ;; full ownership of this script belongs to Sven Neumann.  
  35.  
  36. (define (script-fu-selection-rounded-rectangle image drawable radius concave)
  37.   (gimp-image-undo-group-start image)
  38.  
  39.   (if (= (car (gimp-selection-is-empty image)) TRUE) (gimp-selection-all image))
  40.   (let* ((radius (/ radius 100)) ; convert from percentages 
  41.      (radius (min radius 1.0)) 
  42.      (radius (max radius 0.0)) 
  43.      (select-bounds (gimp-selection-bounds image))
  44.      (has-selection (car select-bounds))
  45.      (select-x1 (cadr select-bounds))
  46.      (select-y1 (caddr select-bounds))
  47.      (select-x2 (cadr (cddr select-bounds)))
  48.      (select-y2 (caddr (cddr select-bounds)))
  49.      (select-width (- select-x2 select-x1))
  50.      (select-height (- select-y2 select-y1))
  51.      (cut-radius 0)
  52.      (ellipse-radius 0))
  53.  
  54.     ;; select to the full bounds of the selection,
  55.     ;; fills in irregular shapes or holes.
  56.     (gimp-rect-select image
  57.               select-x1 select-y1 select-width select-height
  58.               CHANNEL-OP-ADD FALSE 0)
  59.  
  60.     (if (> select-width select-height)
  61.     (set! cut-radius (trunc (+ 1 (* radius (/ select-height 2)))))
  62.     (set! cut-radius (trunc (+ 1 (* radius (/ select-width 2))))))
  63.     (set! ellipse-radius (* cut-radius 2))
  64.  
  65.     ;; cut away rounded (concave) corners
  66.     ; top right
  67.     (gimp-ellipse-select image
  68.              (- select-x1 cut-radius) 
  69.              (- select-y1 cut-radius) 
  70.              (* cut-radius 2) 
  71.              (* cut-radius 2)
  72.              CHANNEL-OP-SUBTRACT
  73.              TRUE
  74.              FALSE 0)
  75.     ; lower left
  76.     (gimp-ellipse-select image
  77.              (- select-x1 cut-radius)
  78.              (- select-y2 cut-radius)
  79.              (* cut-radius 2) 
  80.              (* cut-radius 2) 
  81.              CHANNEL-OP-SUBTRACT
  82.              TRUE
  83.              FALSE 0)
  84.     ; top right
  85.     (gimp-ellipse-select image
  86.              (- select-x2 cut-radius)
  87.              (- select-y1 cut-radius)
  88.              (* cut-radius 2) 
  89.              (* cut-radius 2) 
  90.              CHANNEL-OP-SUBTRACT
  91.              TRUE
  92.              FALSE 0)
  93.     ; bottom left
  94.     (gimp-ellipse-select image
  95.              (- select-x2 cut-radius)
  96.              (- select-y2 cut-radius)
  97.              (* cut-radius 2) 
  98.              (* cut-radius 2) 
  99.              CHANNEL-OP-SUBTRACT
  100.              TRUE
  101.              FALSE 0)
  102.  
  103.     ;; add in rounded (convex) corners
  104.     (if (= concave FALSE)
  105.     (begin 
  106.       (gimp-ellipse-select image
  107.                    select-x1
  108.                    select-y1
  109.                    ellipse-radius
  110.                    ellipse-radius
  111.                    CHANNEL-OP-ADD
  112.                    TRUE
  113.                    FALSE 0)
  114.       (gimp-ellipse-select image
  115.                    select-x1
  116.                    (- select-y2 ellipse-radius)
  117.                    ellipse-radius
  118.                    ellipse-radius
  119.                    CHANNEL-OP-ADD
  120.                    TRUE
  121.                    FALSE 0)
  122.       (gimp-ellipse-select image
  123.                    (- select-x2 ellipse-radius)
  124.                    select-y1
  125.                    ellipse-radius
  126.                    ellipse-radius
  127.                    CHANNEL-OP-ADD
  128.                    TRUE
  129.                    FALSE 0)
  130.       (gimp-ellipse-select image
  131.                    (- select-x2 ellipse-radius)
  132.                    (- select-y2 ellipse-radius)
  133.                    ellipse-radius
  134.                    ellipse-radius
  135.                    CHANNEL-OP-ADD
  136.                    TRUE
  137.                    FALSE 0)))
  138.  
  139.     (gimp-image-undo-group-end image)
  140.     (gimp-displays-flush)))
  141.  
  142.  
  143. (define (script-fu-selection-round image
  144.                    drawable
  145.                                    radius)
  146.   (script-fu-selection-rounded-rectangle image drawable (* radius 100)))
  147.  
  148.  
  149. (script-fu-register "script-fu-selection-rounded-rectangle"
  150.             _"Rounded R_ectangle..."  
  151.             "Converts the current selection, to a rectangular selection with rounded edges. The radius is a percentage of half the selection width or height, whichever is smaller. Select 'Concave' if you want the round edges will to be indented. Round Edges works by subtracting and adding circles to the selection.  "
  152.             "Alan Horkan, Sven Neumann" ; authors
  153.             "Sven Neumann"              ; copyright
  154.             "2004/06/07"
  155.             "*"
  156.             SF-IMAGE       "Image"      0
  157.             SF-DRAWABLE    "Drawable"   0
  158.             SF-ADJUSTMENT _"Radius (%)" '(50 0 100 1 10 0 0)
  159.             SF-TOGGLE     _"Concave"    FALSE)
  160.  
  161. (script-fu-menu-register "script-fu-selection-rounded-rectangle"
  162.              "<Image>/Select/Modify")
  163.  
  164.  
  165. (script-fu-register "script-fu-selection-round"
  166.             ""
  167.             "Rounds the active selection. This procedure exists for backward compatibility only. Please use script-fu-selection-rounded-rectangle instead."
  168.             "Sven Neumann"              ; authors
  169.             "Sven Neumann"              ; copyright
  170.             "1998/02/06"
  171.             "*"
  172.             SF-IMAGE      "Image"           0
  173.             SF-DRAWABLE   "Drawable"        0
  174.             SF-ADJUSTMENT "Relative radius" '(1 0 128 .1 1 1 1))
  175.